﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FourierTransform;

namespace FourierTransformTest
{
    /// <summary>
    /// Summary description for FourierTransformTest
    /// </summary>
    [TestClass]
    public class FourierTransformTest
    {
        public FourierTransformTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void SimpleFourier2D()
        {
            List<Complex> result, compare;
            List<Complex> values = new List<Complex>();
            values.Add(Complex.FromReal(1.0f));
            values.Add(Complex.FromReal(2.0f));
            values.Add(Complex.FromReal(3.0f));
            values.Add(Complex.FromReal(4.0f));
            values.Add(Complex.FromReal(5.0f));
            values.Add(Complex.FromReal(6.0f));
            FourierTransform.FourierTransform.FourierTransform2D(values, 2, 3, out result);
            FourierTransform.FourierTransform.InverseFourierTransform2D(result, 2, 3, out compare);
            float error = 0.0f;
            for (int i = 0; i < values.Count; i++)
            {
                float err = Math.Abs(values[i].RealPart - compare[i].RealPart);
                if (err > error)
                    error = err;
            }

            Assert.IsTrue(error < 0.01f);
        }
    }
}
